import 'package:erp/widgets/load_image.dart';
import 'package:erp/widgets/my_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'controller.dart';

export 'binding.dart';

class Password extends StatelessWidget {
  List<Widget> _buildDivider() {
    return [
      Divider(
        thickness: 2.w,
        color: Color(0xffeeeeee),
        height: 2.h,
      ),
      SizedBox(height: 40.h),
    ];
  }

  _buildPasswordInputWidget({String? placeholder, required TextEditingController controller, required showPassword}) {
    var input = Obx(
      () => TextField(
        maxLines: 1,
        controller: controller,
        obscureText: !showPassword.value,
        keyboardType: TextInputType.text,
        maxLength: 20,
        decoration: InputDecoration(
          floatingLabelBehavior: FloatingLabelBehavior.never,
          counterText: "",
          hintText: '${placeholder}',
          contentPadding: EdgeInsets.only(right: 10.w),
          hintStyle: TextStyle(color: Color(0xFF01527F), fontSize: 24.sp, fontWeight: FontWeight.w400),
          border: InputBorder.none,
          enabledBorder: InputBorder.none,
          focusedBorder: InputBorder.none,
          disabledBorder: InputBorder.none,
          focusedErrorBorder: InputBorder.none,
          errorBorder: InputBorder.none,
        ),
      ),
    );
    return Row(
      children: [
        Expanded(
          child: Container(
            alignment: AlignmentDirectional.center,
            constraints: BoxConstraints(maxHeight: 76.h),
            child: input,
          ),
        ),
        GestureDetector(
          onTap: () {
            showPassword.value = !showPassword.value;
          },
          child: Container(
            width: 40.w,
            child: Obx(
              () => showPassword.value
                  ? LoadAssetImage(
                      "password/eye-open",
                      width: 40.w,
                      height: 30.h,
                    )
                  : LoadAssetImage(
                      "password/eye-close",
                      width: 40.w,
                      height: 30.h,
                    ),
            ),
          ),
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      backgroundColor: Colors.white,
      appBar: MyAppBar(
        backImg: 'assets/images/password/arrow.png',
        title: '',
      ),
      body: GetBuilder<PasswordController>(
        builder: (controller) => Stack(
          children: [
            Positioned(
              left: 59.w,
              top: 47.h,
              child: Text(
                '修改密码',
                style: TextStyle(color: Color(0xFF333333), fontSize: 40.sp, fontWeight: FontWeight.w400),
              ),
            ),
            Positioned(
              left: 60.w,
              right: 60.w,
              top: 188.h,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    "原始密码",
                    style: TextStyle(color: Color(0XFF333333), fontSize: 32.sp, fontWeight: FontWeight.w400),
                  ),
                  _buildPasswordInputWidget(
                    placeholder: '请输入原始密码',
                    controller: controller.originPasswordTextEditingController,
                    showPassword: controller.showOriginPassword,
                  ),
                  ..._buildDivider(),
                  Text(
                    "新密码",
                    style: TextStyle(color: Color(0XFF333333), fontSize: 32.sp, fontWeight: FontWeight.w400),
                  ),
                  _buildPasswordInputWidget(
                    placeholder: '请输入新密码',
                    controller: controller.newPasswordTextEditingController,
                    showPassword: controller.showNewPassword,
                  ),
                  ..._buildDivider(),
                  Text(
                    "确认密码",
                    style: TextStyle(color: Color(0XFF333333), fontSize: 32.sp, fontWeight: FontWeight.w400),
                  ),
                  _buildPasswordInputWidget(
                    placeholder: '请再次输入新密码',
                    controller: controller.repeatPasswordTextEditingController,
                    showPassword: controller.showRepeatPassword,
                  ),
                  ..._buildDivider(),
                ],
                // ,
              ),
            ),
            Positioned(
              bottom: 278.h,
              left: 115.w,
              right: 115.w,
              child: Ink(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [Color(0XFF5FBBFA), Color(0XFF4D8AFE)],
                  ),
                  borderRadius: BorderRadius.all(Radius.circular(40.r)),
                ),
                child: InkWell(
                  borderRadius: BorderRadius.all(Radius.circular(40.r)),
                  onTap: () {
                    controller.submit();
                  },
                  splashColor: Color(0XFF5FBBFA),
                  child: Container(
                    alignment: AlignmentDirectional.center,
                    width: 520.w,
                    height: 80.w,
                    child: Text(
                      "保存并重新登录",
                      style: TextStyle(color: Colors.white, fontSize: 36.sp, fontWeight: FontWeight.w400),
                    ),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
